package com.baomidou;

import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.po.TableField;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;
import com.baomidou.mybatisplus.generator.type.ITypeConvertHandler;
import com.baomidou.mybatisplus.generator.type.TypeRegistry;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.type.JdbcType;

@Slf4j
public class CustomizedMSSQLTypeHandler implements ITypeConvertHandler {
    @Override
    public IColumnType convert(GlobalConfig globalConfig,
                               TypeRegistry typeRegistry,
                               TableField.MetaInfo metaInfo) {
        if (JdbcType.BIT.equals(metaInfo.getJdbcType())
                || JdbcType.TINYINT.equals(metaInfo.getJdbcType())
                || JdbcType.SMALLINT.equals(metaInfo.getJdbcType())
                || JdbcType.BOOLEAN.equals(metaInfo.getJdbcType())) {
            return DbColumnType.INTEGER;
        }
        return typeRegistry.getColumnType(metaInfo);
    }
}